#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

VERSION=arduino-1.8.16

if [ -f ~/.local/share/$VERSION/uninstall.sh ];then
  cd ~/.local/share
  $VERSION/uninstall.sh || error "Failed to run uninstall.sh as $USER user"
  sudo $VERSION/uninstall.sh || error "Failed to run uninstall.sh as root user"
  rm -rf $VERSION || error "Failed to remove $VERSION folder"
  cd
else
  echo "WARNING: Arduino's uninstall.sh script was not found! Most likely it was never fully installed."
fi

exit 0
